<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/4/13
  Time: 13:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <%--<form class="layui-form layui-col-md12 x-so">

            <input type="text" id="eNumber" placeholder="请输入7位员工编号查询" class="layui-input">
            <button class="layui-btn" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
            </button>
        </form>--%>
            <form class="layui-form layui-col-md12 x-so">
                <input type="text" id="eNumber" placeholder="请输入7位员工编号查询" class="layui-input">
                <a class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></a>
            </form>
    </div>
    <xblock>

        <button class="layui-btn"
                onclick="x_admin_show('添加用户','${pageContext.request.contextPath}/employee/addEmployeePage')"><i
                class="layui-icon"></i>添加员工信息
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span id="countData"></span> 条 &nbsp;&nbsp;&nbsp;&nbsp;<span
                id="countpage"></span> 页   </span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>编号</th>
            <th>账号</th>
            <th>密码</th>
            <th>姓名</th>
            <th>部门</th>
            <th>职位</th>
            <th>年龄</th>
            <th>性别</th>
            <th>邮箱</th>
            <th>电话</th>
            <th>操作</th>
        </thead>
        <tbody id="tb">


        </tbody>
    </table>
    <div class="page">
        <div>
            <button class="prev" onclick="pre()">上一页</button>

            <%--            <span class="current">1</span>--%>

            <button class="next" onclick="next()">下一页</button>
        </div>
    </div>

</div>
<script>
    //分页显示
    var page = 1;
    var row = 2;
    var totalPages = 0;

    $(function() {
        load();
    });

    //上一页
    function pre() {
        page--;
        if (page < 1) {
            page = 1;
        }
        load();
    }

    //下一页
    function next() {
        page++;
        if (page > totalPages) {
            page = totalPages;
        }
        load();
    }


    /*用户-删除*/
    function member_del(obj) {
        let is = confirm("你确定要删除吗？");
        if (is) {
            let id = $(obj).parent().parent().find("td").eq(1).text();
            console.log(id)
            $.ajax({
                url: "${pageContext.request.contextPath}/employee/deleteBysId",
                type: "get",
                data: {"id": id},
                dataType: "json",
                success: function (data) {
                    alert(data.info);
                    load();//回显删除完之后的数据
                }
            });
        }
    }


    //修改员工信息
    // function x_admin_show() {
    // let id = $(obj).parent().parent().find("td").eq(1).text();
    <%--$.ajax({--%>
    <%--    url:"${pageContext.request.contextPath}/employee/editPage",--%>
    <%--    type:"get",--%>
    <%--    data:{"id":id},--%>
    <%--    dataType:"json",--%>
    <%--    --%>
    <%--})--%>
    // }

    function load() {
        var str = $("#eNumber").val();
        console.log(str);
        $.ajax({
            url: "${pageContext.request.contextPath}/employee/employeeList",
            type: "post",
            contentType: "application/x-www-form-urlencoded",
            data: {"eNumber": str, "page": page, "row": row},
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (typeof (data.info) == "string") {
                    $("#tb").html("");
                } else {
                    //取出总页数
                    totalPages = data.pages;
                    //显示总条数
                    $("#countData").text(data.total);
                    //显示总页数
                    $("#countpage").text(data.pages);
                    var html = "";
                    for (var i = 0; i < data.info.length; i++) {
                        html += "<tr>" +
                            "<td>" +
                            "   <div class=\"layui-unselect layui-form-checkbox\" lay-skin=\"primary\" data-id='2'><i class=\"layui-icon\">&#xe605;</i></div>" +
                            "</td>" +
                            "<td>" + data.info[i].id + "</td>" +
                            "<td>" + data.info[i].eNumber + "</td>" +
                            "<td>" + data.info[i].eName + "</td>" +
                            "<td>" + data.info[i].ePwd + "</td>" +
                            "<td>" + data.info[i].name + "</td>" +
                            "<td>" + data.info[i].depa + "</td>" +
                            "<td>" + data.info[i].job + "</td>" +
                            "<td>" + data.info[i].age + "</td>" +
                            "<td>" + data.info[i].sex + "</td>" +
                            "<td>" + data.info[i].eMail + "</td>" +
                            "<td>" + data.info[i].phone + "</td>" +

                            "<td class='td-manage'>" +
                            "        <a title=\"编辑信息\" onclick=\"x_admin_show('修改信息','${pageContext.request.contextPath}/employee/employeeEditPage')\"href=\"javascript:;\">\n" +
                            "                    <i class=\"layui-icon\">&#xe642;</i>\n" +
                            "                </a>" +
                            " <a title=\"删除员工\" onclick=\"member_del(this,'要删除的id')\" href=\"javascript:;\">\n" +
                            "                <i class=\"layui-icon\">&#xe640;</i>\n" +
                            "              </a>" +
                            "</td>" +
                            //    this指当前标签，这里就指向 button标签（写在哪个标签就是哪个标签）
                            "</tr>";
                    }
                    $("#tb").html(html)
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                alert(xhr.statusText);
            },
        })
    }

    //layui监听器
    layui.use(['form', 'laypage', 'laydate'], function(){
        var form = layui.form;
        //search按钮事件
        form.on('submit(sreach)', function(data){
            console.log(data);
            load();
            return false;
        });

        // form提交
        form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
    });
</script>
</body>
</html>
